package com.example.redisstudy;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


public class InsuranceFilter {

    public static void main(String[] args) {
        // 假设代理人等级为2，保险列表包含多个保险对象
        int agentLevel = 4;
        List<Insurance> insuranceList = new ArrayList<>();
        // 添加多个保险对象到列表中
        insuranceList.add(new Insurance(1, "Insurance 1", 1));
        insuranceList.add(new Insurance(2, "Insurance 2", 2));
        insuranceList.add(new Insurance(3, "Insurance 3", 3));
        insuranceList.add(new Insurance(4, "Insurance 4", 4));

        // 使用Stream API过滤符合当前代理人等级的保险对象
        List<Insurance> filteredInsuranceList = insuranceList.stream()
                .filter(insurance -> insurance.getInsuranceLevel() >= agentLevel)
                .collect(Collectors.toList());

        // 打印过滤后的保险列表
        System.out.println("Filtered Insurance List:");
        filteredInsuranceList.forEach(System.out::println);
    }
}

class Insurance {
    private int id;
    private String name;
    private int insuranceLevel;

    public Insurance(int id, String name, int insuranceLevel) {
        this.id = id;
        this.name = name;
        this.insuranceLevel = insuranceLevel;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public int getInsuranceLevel() {
        return insuranceLevel;
    }

    @Override
    public String toString() {
        return "Insurance{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", insuranceLevel=" + insuranceLevel +
                '}';
    }
}
